﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Yeap.Kernel.Utils;
using Yeap.Kernel.Utils.Enums;

namespace Yeap.Kernel.Storage
{
    public class WorkRepository : RepositoryBase<Work>, IWorkRepository
    {
        public IEnumerable<Work> GetWorks(int course = 0, WorkTypes workType = WorkTypes.None, Professor professor = null, Int32 year = 0)
        {
            IEnumerable<Work> resultWorks = query;
            if (course != 0)
            {
                if (course < SiteSettingPool.MinimalCourse || course > SiteSettingPool.MaximalCourse)
                {
                    throw new ArgumentOutOfRangeException("course");
                }
                resultWorks = resultWorks.Where(w => w.Course == course);
            }

            if (workType != WorkTypes.None)
            {
                resultWorks = resultWorks.Where(w => w.GetWorkType() == workType);
            }

            if (professor != null)
            {
                resultWorks = resultWorks.Where(w => w.ProfessorId == professor.Id);
            }

            if (year != 0)
            {
                resultWorks = resultWorks.Where(w => w.Year == year);
            }
            return resultWorks;

            
            
        }

        public IEnumerable<Work> GetCurrentYearWorks(int course = 0, 
                                                    WorkTypes workType = WorkTypes.None,
                                                    Professor professor = null)
        {
            return GetWorks(course, workType, professor, SiteSettingPool.CurrentYear);
        }
    }
}